﻿using UnityEngine;
using System.Collections;
using UnityEditor;
using System;

namespace Hont.HyperWigglePackage.Editor
{
    public class Invert : BaseWigglePlugins
    {
        bool mIsInvertPX;
        bool mIsInvertPY;
        bool mIsInvertPZ;

        bool mIsInvertRX;
        bool mIsInvertRY;
        bool mIsInvertRZ;


        public override void Execute(HyperWiggleEditorCore core)
        {
            base.Execute(core);
        }

        protected override void OnExit()
        {
        }

        protected override void OnGUI()
        {
            mIsInvertPX = EditorGUILayout.Toggle("Invert PX", mIsInvertPX);
            mIsInvertPY = EditorGUILayout.Toggle("Invert PY", mIsInvertPY);
            mIsInvertPZ = EditorGUILayout.Toggle("Invert PZ", mIsInvertPZ);

            mIsInvertRX = EditorGUILayout.Toggle("Invert RX", mIsInvertRX);
            mIsInvertRY = EditorGUILayout.Toggle("Invert RY", mIsInvertRY);
            mIsInvertRZ = EditorGUILayout.Toggle("Invert RZ", mIsInvertRZ);

            if (GUILayout.Button("Apply"))
            {
                for (int i = 0; i < mCore.FrameData.Length; i++)
                {
                    var pr = mCore.FrameData[i];
                    if (mIsInvertPX)
                        pr.RelativePosition.x *= -1;
                    if (mIsInvertPY)
                        pr.RelativePosition.y *= -1;
                    if (mIsInvertPZ)
                        pr.RelativePosition.z *= -1;

                    if (mIsInvertRX)
                        pr.RelativeRotation.x *= -1;
                    if (mIsInvertRY)
                        pr.RelativeRotation.y *= -1;
                    if (mIsInvertRZ)
                        pr.RelativeRotation.z *= -1;

                    mCore.FrameData[i] = pr;
                }
            }

            HyperWiggleUtil.StableOffset(mCore.FrameData);

            mCore.UpdatePreview();
            mCore.UpdateTimeline();
        }
    }
}